package com.dao;

import java.util.List;
import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * PointEquipmentTb entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.dao.PointEquipmentTb
 * @author MyEclipse Persistence Tools
 */

public class PointEquipmentTbDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(PointEquipmentTbDAO.class);
	// property constants
	public static final String EQUIP_PID = "equipPid";
	public static final String EQUIP_NAME = "equipName";
	public static final String EQUIP_SHORTNAME = "equipShortname";
	public static final String EQUIP_CODE = "equipCode";
	public static final String EQUIP_PIPENET_ID = "equipPipenetId";
	public static final String EQUIP_TYPE = "equipType";
	public static final String EQUIP_NATURE = "equipNature";
	public static final String EQUIP_VALID = "equipValid";
	public static final String EQUIP_LEVEL = "equipLevel";
	public static final String EQUIP_IMAGE = "equipImage";
	public static final String EQUIP_MARK = "equipMark";
	public static final String ORG_ID = "orgId";

	public void save(PointEquipmentTb transientInstance) {
		log.debug("saving PointEquipmentTb instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(PointEquipmentTb persistentInstance) {
		log.debug("deleting PointEquipmentTb instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public PointEquipmentTb findById(java.lang.Integer id) {
		log.debug("getting PointEquipmentTb instance with id: " + id);
		try {
			PointEquipmentTb instance = (PointEquipmentTb) getSession().get(
					"com.dao.PointEquipmentTb", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(PointEquipmentTb instance) {
		log.debug("finding PointEquipmentTb instance by example");
		try {
			List results = getSession().createCriteria(
					"com.dao.PointEquipmentTb").add(Example.create(instance))
					.list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding PointEquipmentTb instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from PointEquipmentTb as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByEquipPid(Object equipPid) {
		return findByProperty(EQUIP_PID, equipPid);
	}

	public List findByEquipName(Object equipName) {
		return findByProperty(EQUIP_NAME, equipName);
	}

	public List findByEquipShortname(Object equipShortname) {
		return findByProperty(EQUIP_SHORTNAME, equipShortname);
	}

	public List findByEquipCode(Object equipCode) {
		return findByProperty(EQUIP_CODE, equipCode);
	}

	public List findByEquipPipenetId(Object equipPipenetId) {
		return findByProperty(EQUIP_PIPENET_ID, equipPipenetId);
	}

	public List findByEquipType(Object equipType) {
		return findByProperty(EQUIP_TYPE, equipType);
	}

	public List findByEquipNature(Object equipNature) {
		return findByProperty(EQUIP_NATURE, equipNature);
	}

	public List findByEquipValid(Object equipValid) {
		return findByProperty(EQUIP_VALID, equipValid);
	}

	public List findByEquipLevel(Object equipLevel) {
		return findByProperty(EQUIP_LEVEL, equipLevel);
	}

	public List findByEquipImage(Object equipImage) {
		return findByProperty(EQUIP_IMAGE, equipImage);
	}

	public List findByEquipMark(Object equipMark) {
		return findByProperty(EQUIP_MARK, equipMark);
	}

	public List findByOrgId(Object orgId) {
		return findByProperty(ORG_ID, orgId);
	}

	public List findAll() {
		log.debug("finding all PointEquipmentTb instances");
		try {
			String queryString = "from PointEquipmentTb";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public PointEquipmentTb merge(PointEquipmentTb detachedInstance) {
		log.debug("merging PointEquipmentTb instance");
		try {
			PointEquipmentTb result = (PointEquipmentTb) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(PointEquipmentTb instance) {
		log.debug("attaching dirty PointEquipmentTb instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(PointEquipmentTb instance) {
		log.debug("attaching clean PointEquipmentTb instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}